package akjvm.tools.java.classpath;

import java.io.File;
import java.io.IOException;
import java.nio.file.*;

/**
 * Created by VictoryWang on 2016/6/23.
 */
public class WildcardEntry extends Entry{

    private CompositeEntry entry;


    public WildcardEntry(String path) throws IOException {

        String folder = path.substring(0, path.length() - 1);
        StringBuilder jarPaths = new StringBuilder();
        Path folderPath = Paths.get(folder);
        if (Files.exists(folderPath)) {
            Files.newDirectoryStream(folderPath,"*.{jar,JAR}").forEach(cur -> jarPaths.append(cur).append(File.pathSeparatorChar));
            entry = new CompositeEntry(jarPaths.toString());
        }
    }

    @Override
    public byte[] readClass(String className) throws IOException {
        return entry.readClass(className);
    }

    @Override
    public String toString() {
        return entry.toString();
    }
}
